package org.leeloo.databinding.internal.ui;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.leeloo.databinding.ui.test.support.PluginTestCase;

public class ClearViewerActionTest extends PluginTestCase {
    private TableViewer viewer;
    private Shell shell;
    private List input;
    
    protected void setUp() throws Exception {
        super.setUp();
        shell = new Shell();
        
        viewer = new TableViewer(shell);
        viewer.setContentProvider(new ArrayContentProvider());
        input = new ArrayList();
        input.add("item");
        viewer.setInput(input);
    }
    
    public void testConstruction() throws Exception {
        ClearViewerAction action = new ClearViewerAction(viewer, input);
        assertNotNull(action.getImageDescriptor());
        
        assertNotNull(action.getText());
        assertNotNull(action.getToolTipText());
    }
    
    public void testRun() throws Exception {
        Table table = viewer.getTable();
        assertEquals(1, input.size());
        assertEquals(input.size(), table.getItemCount());
        
        ClearViewerAction action = new ClearViewerAction(viewer, input);
        action.run();
        
        assertEquals(0, input.size());
        assertEquals(input.size(), table.getItemCount());
    }
}
